﻿using System;
using System.Threading;

namespace MyFramework.Common
{
    /// <summary>
    /// custom property
    /// </summary>
    public class CustomProperty : Entity
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomProperty"/> class.
        /// </summary>
        public CustomProperty(string name, object value)
        {
            this.Name = name;
            this.Value = value;
        }

        #region Name Property

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        public String Name
        {
            get { return this._name; }
            set { if (this._name != value) { this._name = value; RaisePropertyChangedEvent(() => Name); } }
        }
        private String _name;
        #endregion

        #region Value Property

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>
        /// The value.
        /// </value>
        public object Value
        {
            get { return this._value; }
            set { if (this._value != value) { this._value = value; RaisePropertyChangedEvent(() => Value); } }
        }
        private object _value;
        #endregion

        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T GetValue<T>()
        {
            return (T)Convert.ChangeType(this._value, typeof(T), Thread.CurrentThread.CurrentCulture);
        }
    }
}
